# -*- coding:utf8-*-
import pymongo
import pymysql
import redis


def mysql_demo():
    mysqldb = pymysql.connect(host='192.168.19.128', user='root', password='123456', port=3306, database='spider')
    cursor = mysqldb.cursor()
    cursor.execute("select version()")
    data = cursor.fetchone()
    print('database table version: %s ' % data)
    mysqldb.close()


def mongo_demo():
    myclient = pymongo.MongoClient("mongodb://admin:123456@192.168.19.128:27017")
    dblist = myclient.list_database_names()
    for db_name in dblist:
        print(db_name)
    spider_db = myclient['spider']
    col_list = spider_db.list_collection_names()
    for col_nm in col_list:
        print(col_nm)
    myclient.close()


def redis_demo():
    r_demo = redis.Redis(host='192.168.19.128', port=6379, decode_responses=True, password='123456')
    print(r_demo.get('name'))


if __name__ == '__main__':
    # mysql_demo()
    # mongo_demo()
    redis_demo()
